package com.hfdg.organization.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hfdg.prototype.base.utils.TimeUtils;
import com.hfdg.organization.mapper.StationMapper;
import com.hfdg.organization.entity.Station;
import com.hfdg.organization.service.StationService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Random;
import java.util.UUID;

/**
 * @ClassName StationServiceImpl
 * @Description TODO
 * @Author yuelh
 * @Date 2019/1/19 18:26
 * @Version 1.0
 * @Company 会飞的锅工作室
 **/
@Service
public class StationServiceImpl implements StationService {
    @Autowired
    StationMapper stationMapper;

    @Override
    public String insert(Station station) {
        String uid = UUID.randomUUID().toString();
        station.setUid(uid);
        station.setDelFlag("0");
        station.setCreateTime(new Date());
        stationMapper.insert(station);
        return uid;
    }

    @Override
    public Integer update(Station station) {
        station.setUpdateTime(new Date());
        return stationMapper.update(station);
    }

    @Override
    public Integer  delete(String uid) {
        return stationMapper.delete(uid);
    }
    @Override
    public Integer batchDelete(String[] uids) {
            return stationMapper.batchDelete(uids);
    }

    @Override
    public Station get(String uid) {
        return stationMapper.get(uid);
    }

    @Override
    public List<Station> list(Station station) {
    return  stationMapper.list(station);
    }

    @Override
    public PageInfo<Station> getPagingData(int offset, int limit,String orderBy, Station station) {
        if(null==orderBy|| StringUtils.isBlank(orderBy)){
        PageHelper.startPage((offset/limit)+1,limit);
        }else{
        PageHelper.startPage((offset/limit)+1,limit,orderBy);
        }
        PageInfo<Station> pageInfo =new PageInfo<>(stationMapper.list(station));
            return pageInfo;
            }
    @Override
    public String insertOrUpdate(Station station){
        if(null!=station.getUid()){
            this.update(station);
        }else{
            this.insert(station);
        }
        return station.getUid();
    }
            }
